package com.cl.blog.web.manager;

import cn.hutool.core.lang.Assert;
import cn.hutool.core.map.MapUtil;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cl.blog.annotation.Login;
import com.cl.blog.common.Result;
import com.cl.blog.entity.BContent;
import com.cl.blog.exception.WebException;
import com.cl.blog.service.BContentService;
import com.cl.blog.vo.AdminSearchVo;
import com.cl.blog.web.PageController;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author 付
 * @Date 2024-03-17 14:05
 * @Version 1.0
 * @description
 * @since 1.0
 */

@RestController
@RequestMapping("/admin/content")
public class AdminContentController extends PageController {

	@Resource
	BContentService bContentService;

	@GetMapping("/list")
//	@Login(issuer = "ADMIN")
	public Result list(Long id,@RequestParam("page") Long currentPage){
		System.out.println("获取的id----"+id+"----page---"+currentPage);
		return Result.success(bContentService.PageList(new Page(currentPage,10),id));
	}

	@PostMapping("/delete")
	public Result delete(@RequestBody List<Integer> ids){
		System.out.println("执行了--->"+ids);
		Assert.notNull(ids,"抱歉，提交的数据为空");
		// 删除数据
		boolean b = bContentService.removeBatchByIds(ids);
		Assert.isTrue(b,"抱歉，出错了");
		return Result.success();
	}

	@PostMapping("/reexamine")
	public Result reExamine(@RequestBody List<Integer> ids){
		System.out.println(ids);
		Assert.notNull(ids,"抱歉，提交的数据为空");
		boolean b = bContentService.update(new UpdateWrapper<BContent>()
				.in("id", ids)
				.set("status", 1)
		);
		Assert.isTrue(b,"提交失败");
		return Result.success();
	}


	@PostMapping("/search")
	public Result search(@RequestBody AdminSearchVo adminSearchVo){
		Assert.notNull(adminSearchVo,"抱歉，查询条件不能为空");
		adminSearchVo.setTitle(adminSearchVo.getTitle().trim());
		return Result.success(bContentService.searchPage(new Page<BContent>(0,10),adminSearchVo));
	}
}
